package com.yidu.t299.dao.cfj;

import com.yidu.t299.domain.cfj.TimeClock;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TimeClockMapper {
    /**
     * 根据编号删除信息
     * @param annalId 编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
            "delete from time_clock" +
                    " where annal_id = #{annal_id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer annalId);

    /**
     * 添加信息
     * @param timeClock
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
            "insert into time_clock (annal_id,record_id,begin_date,end_date,diligent_date,duty_state)" +
                    " values (#{annalId,jdbcType=INTEGER},#{recordId,jdbcType=INTEGER}," +
                    "#{beginDate,jdbcType=VARCHAR},#{endDate,jdbcType=VARCHAR}," +
                    "#{diligentDate,jdbcType=VARCHAR},#{dutyState,jdbcType=VARCHAR})"
    })
    int insert(TimeClock timeClock);

    /**
     * 根据编号查询指定的信息
     * @param annalId
     * @return
     */
    @Select({
            "select annal_id,t.record_id,r.record_name,begin_date,end_date,diligent_date,duty_state from time_clock t " +
                    "join record r on r.record_id = t.record_id" +
                    " where annal_id = #{annalId,jdbcType=INTEGER}"
    })
    @Results(id = "TimeClockMap",value = {
            @Result(id = true,column = "annal_id",property = "annalId"),
            @Result(column = "record_id",property = "recordId"),
            @Result(column = "record_name",property = "recordName"),
            @Result(column = "begin_date",property = "beginDate"),
            @Result(column = "end_date",property = "endDate"),
            @Result(column = "diligent_date",property = "diligentDate"),
            @Result(column = "duty_state",property = "dutyState")
    })
    TimeClock selectByPrimaryKey(Integer annalId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 对象集合
     */
    @Select("select * from (select annal_id,t.record_id,r.record_name,begin_date,end_date,diligent_date,duty_state from time_clock t " +
            "join record r on r.record_id = t.record_id) tr   where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("TimeClockMap")
    List<TimeClock> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from (select annal_id,t.record_id,r.record_name,begin_date,end_date,diligent_date,duty_state from time_clock t " +
            "join record r on r.record_id = t.record_id) tr  where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据信息修改其数据
     * @param timeClock
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update time_clock" +
                    " set record_id = #{recordId,jdbcType=INTEGER},",
            " begin_date = #{beginDate,jdbcType=VARCHAR}, " +
                    " end_date = #{endDate,jdbcType=VARCHAR}, " +
                    " diligent_date = #{diligentDate,jdbcType=VARCHAR}," +
                    " duty_state = #{dutyState,jdbcType=VARCHAR}" +
                    " where annal_id = #{annalId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TimeClock timeClock);
}